using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Park.Net.IService;
using Park.Net.Model;
using Park.Net.Utils;

namespace Park.Net.ParkWebAPI.Controllers
{
    // 查
    [ApiController]
    [Route("api/[controller]")]
    public class OwnerController : ControllerBase
    {       
        private readonly IBaseServices<CarPark> _OwnerService;

        public OwnerController(IBaseServices<CarPark> OwnerService)
        {
            _OwnerService = OwnerService;
        }

        [HttpGet("Owner")]
        public async Task<ActionResult<ApiReturns>> GetOwner()
        {
            var res = await _OwnerService.FindAllAsync();
            if (res != null && res.Count > 0)
            {
                return ApiReturnsHelper.Succeed(res);
            }
            return ApiReturnsHelper.Failed("查不到~");
        }
    }
     // 添加
public class OwnerAddController : ControllerBase
{
    private readonly IBaseServices<Owner> _context;

    public OwnerAddController(IBaseServices<Owner> context)
    {
        _context = context;
    }

    // POST: api/Bike/AddBike
    [HttpPost]
    [Route("OwnerAdd")]
    public async Task<ActionResult> AddBike(Owner bike )
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        // Perform additional validation as needed
        if (string.IsNullOrEmpty(bike.Name) || string.IsNullOrEmpty(bike.Password)|| string.IsNullOrEmpty(bike.Phone))
        {
            return BadRequest("Bike number and type are required fields.");
        }

        // Add bike data to the database
       await _context.CreateAsync(bike);
      
        return Ok($"Bike with ID {bike.ID} was added successfully.");
    }
}
}
